#include <iostream>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#include <boost/smart_ptr.hpp>
#include <boost/make_shared.hpp>
#include <boost/typeof/typeof.hpp>
#include <boost/bind.hpp>


class Trace
{
public:
	Trace(){ std::cout << "Trace constructed" << std::endl; }
	~Trace(){ std::cout << "Trace destructed" << std::endl; }
};

int main( int argc, char *argv[] )
{
	boost::shared_ptr< int > sp( new int(3) );
	BOOST_AUTO( sp1, sp );
	std::cout << "unique: " << sp.unique() << " use_count: " << sp.use_count() << " sp: " <<  sp << std::endl;
	sp.reset();
	std::cout << "unique: " << sp.unique() << " use_count: " << sp.use_count() << " sp: " <<  sp << std::endl;
	std::cout << "unique: " << sp1.unique() << " use_count: " << sp1.use_count() << " sp1: " <<  sp1 << std::endl;

	*sp1 = 4;
	std::cout << "sp1 value: " << *sp1 << std::endl;

	boost::shared_ptr< FILE > fp( ::fopen( "/dev/null", "r" ), ::fclose );
	assert( EOF == fgetc( fp.get() ) );

	int fd = ::open( "/dev/null", O_RDONLY );
	boost::shared_ptr< void > fd_guard( static_cast< void * >( NULL ), boost::bind(close, fd) );
	assert( 0 == read( fd, sp.get(), 1 ) );

	// boost::shared_ptr< int > sp2 = boost::make_shared< int >( 5 );
	// std::cout << "sp2 value: " << *sp2 << std::endl;
	

	return 0;
}

// note : http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml?showone=Smart_Pointers#Smart_Pointers
